package com.comita.selenium.applogic;


import java.util.concurrent.TimeUnit;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.WebDriverWait;

import com.comita.selenium.util.Browser;
import com.comita.selenium.util.PropertyLoader;
import com.comita.selenium.webdriver.WebDriverFactory;



public class ApplicationManager {
	
	  public String baseUrl;
	  private String gridHubUrl;
	  private String username;
	  private String password;
	  private WebDriver driver;
	  private MailHelper mailHelper;
	  private UserHelper userHelper;
	  private FilmHelper filmHelper;
	  private WebDriverWait wait;
	  
	  public ApplicationManager(){
		  baseUrl = PropertyLoader.loadProperty("site.url");
		  gridHubUrl = PropertyLoader.loadProperty("grid2.hub");

		  Browser browser = new Browser();
		  browser.setName(PropertyLoader.loadProperty("browser.name"));
		  browser.setVersion(PropertyLoader.loadProperty("browser.version"));
		  browser.setPlatform(PropertyLoader.loadProperty("browser.platform"));

		  username = PropertyLoader.loadProperty("user.username");
		  password = PropertyLoader.loadProperty("user.password");		  
		  
		  driver = WebDriverFactory.getInstance(gridHubUrl, browser, username, password);
		  
		  mailHelper = new MailHelper(this);
		  userHelper = new UserHelper(this);
		  filmHelper = new FilmHelper(this);
		  //getNavigationHelper().openMainPage();
		  //driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
		  wait = new WebDriverWait(driver, 30);
		  
	  }
	
	  public void stop() {
	    if (getWebDriver() != null) {
	      getWebDriver().quit();
	    }
	  }

	public WebDriver getWebDriver() {
		return driver;
	}

	public void setDriver(WebDriver driver) {
		this.driver = driver;
	}	
	
	/*public NavigationHelper getNavigationHelper(){
		return navigationHelper;
	}*/
	
	protected String getBaseUrl() {
	    return baseUrl;
	}	
	
	public MailHelper getMailHelper() {
		return mailHelper;
	}

	public UserHelper getUserHelper(){
		return userHelper;
	}
	
	public FilmHelper getFilmHelper(){
		return filmHelper;
	}
}
